package com.hmdp.config;

import com.hmdp.utils.LogInInterceptor;
import com.hmdp.utils.RefreshInterceptor;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.Configuration;
import org.springframework.web.servlet.config.annotation.InterceptorRegistry;
import org.springframework.web.servlet.config.annotation.WebMvcConfigurationSupport;
import org.springframework.web.servlet.config.annotation.WebMvcConfigurer;

@Configuration
public class WebMvcConfiguration implements WebMvcConfigurer {
    @Autowired
    private LogInInterceptor logInInterceptor;
    @Autowired
    private RefreshInterceptor refreshInterceptor;
    @Override
    public void addInterceptors(InterceptorRegistry registry) {
        registry.addInterceptor(logInInterceptor)
                .addPathPatterns("/**")
                .excludePathPatterns(
                    "/user/code",
                    "/user/login",
                    "blog/hot",
                    "/shop/**",
                    "shop-type/**",
                    "/voucher/**"
                ).order(1);//放行的都是不登录用户应该也能做的事（功能）
        registry.addInterceptor(refreshInterceptor)
                .addPathPatterns("/**").order(0);// order表示拦截器的执行顺序，可以点进addInterceptor()方法,order属于InterceptorRegistration属性
    }
}
